<?php
require_once(dirname(dirname(__FILE__)).'/vendor/autoload.php');
use app\controller\UserController as UserController;

$data = file_get_contents('php://input','r');

if($data == null || $data == '') {
    echo json_encode(["error"=>"no param"]);
    die;
}
$data = getParam($data);

if(empty($data['act'])) {
    echo json_encode(["error"=>"no param"]);
    die;
}

$user = new UserController;

switch ($data['act']) {
	case 'login':
		$user->login($data['phone'], $data['password'], $data['location']);
		break;

	case 'register':
		$user->register($data['phone'], $data['password'], $data['location']);
		break;

	case 'self':
		# code...
		break;

	case 'logout':
		# code...
		break;
	
	default:
		#var_dump($user);
		echo json_encode(["error"=>"no param"]);die;
		break;
}

function getParam($data) {
    $rs = explode('&', $data);
    $param = [];
    foreach($rs as $k=>$v) {
	$_rs = explode('=', $v);
	$param[$_rs[0]] = $_rs[1];
    }
    return $param;
}
